import { onMounted } from 'vue'
import { RouteRecordName, useRoute } from 'vue-router'
import { useStore } from '/@/store'
import { getUser } from '../util/auth'
import { getUserInfo } from '../util/business-util'

const whiteRouteList: RouteRecordName[] = []

export function useUserInfo() {
  const { commit, state } = useStore()
  const route = useRoute()

  onMounted(async () => {
    if (whiteRouteList.includes(route.name || '')) {
      return
    }
    const ctr_user = JSON.parse(getUser())

    await getUserInfo(commit, state, ctr_user.userId, true)
  })
}
